package org.usmile.algorithms.huawei.acm;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

// https://blog.csdn.net/qq_34465338/article/details/128357540
public class _寻找符合要求的最长子串 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char specialChar = sc.nextLine().charAt(0);
        String str = sc.nextLine();
        Map<Character, Integer> windowChars = new HashMap<>();
        int max = 0;
        int left = 0;
        int right = 0;
        while (right < str.length()) {
            char curr = str.charAt(right);
            if (curr == specialChar) {
                right++;
                left = right;
                windowChars.clear();

                continue;
            }
            windowChars.put(curr, windowChars.getOrDefault(curr, 0) + 1);
            while (windowChars.get(curr) >= 3) {
                char leftChar = str.charAt(left);
                windowChars.put(leftChar, windowChars.get(leftChar) - 1);
                left++;
            }

            max = Math.max(max, right - left + 1);

            right++;
        }

        System.out.println(max);
    }
}
